package com.lzj.demo.design.adapter;

import cn.hutool.json.JSONUtil;
import com.lzj.demo.design.adapter.dto.CreateAccount;
import com.lzj.demo.design.adapter.dto.OrderMq;
import com.lzj.demo.design.adapter.dto.RebateInfo;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Slf4j
public class TestMqAdapter {
    public static void main(String[] args) throws Exception {
        CreateAccount account = new CreateAccount();
        account.setNumber("1001");
        account.setAddress("福建沙县");
        account.setAccountDate(new Date());
        account.setDesc("在校开户");
        Map<String,String> link01 = new HashMap<>();
        link01.put("userId","number");
        link01.put("bizId","number");
        link01.put("bizTime","accountDate");
        link01.put("desc","desc");
        RebateInfo rebateInfo01 = MqAdapter.adapter(JSONUtil.toJsonStr(account),link01);
        log.info("适配前:{}",account);
        log.info("适配后:{}", JSONUtil.toJsonStr(rebateInfo01));

        OrderMq orderMq = new OrderMq();
        orderMq.setUid("1001");
        orderMq.setOrderId("Order001");
        orderMq.setSku("sku001");
        orderMq.setCreateOrderTime(new Date());

        Map<String,String> link02 = new HashMap<>();
        link02.put("userId","uid");
        link02.put("bizId","orderId");
        link02.put("bizTime","createOrderTime");

        RebateInfo rebateInfo02 = MqAdapter.adapter(JSONUtil.toJsonStr(orderMq),link02);
        log.info("适配前:{}",orderMq);
        log.info("适配后:{}",JSONUtil.toJsonStr(rebateInfo02));
    }
}
